/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BLL;

import DAL.MyConnectUnit;
import DTO.Roles;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.HashSet;

/**
 *
 * @author Quan_Nuce
 */
public class BRoles {
      MyConnectUnit connect;
     public BRoles() {
        this.connect = DAL.DAL.getDAL();
}

public HashSet<Roles>getRoless(String condition, String OderBy) throws Exception{
        ResultSet result = this.connect.Select("Roles",condition,OderBy);
        HashSet<Roles> roless = new HashSet<Roles>();
        while(result.next()){
            Roles roles = new Roles();
            roles.setRoleID(result.getInt("RoleID"));
            roles.setFunctionName(result.getString("FunctionName"));
           roles.setRoleName(result.getString("RoleName"));
          
                roless.add(roles);
        }
        return roless;
    }
 public HashSet<Roles>getRoless(String condition) throws Exception{
        return getRoless(condition,null);
    }
  public HashSet<Roles>getRoless() throws Exception{
        return getRoless(null);
    }
   
   public Roles getByID(int id)throws Exception{
        HashSet<Roles>roless = this.getRoless("RoleID = "+ id);
        if(roless.size()>0)
            return roless.toArray(new Roles[roless.size()])[0];
        return null;
       
   }
   public void Insert(Roles roles)throws Exception{
        HashMap<String, Object>map = new HashMap<String,Object>();
        map.put("RoleID", roles.getRoleID());
        map.put("FunctionName", roles.getFunctionName());
        map.put("RoleName", roles.getRoleName());
       
       
        this.connect.Insert("Roles", map);
       
   }
     public void Inserts(HashSet<Roles> roless)throws Exception{
        for(Roles roles:roless)
            this.Insert(roles);
       
   }
    public void Update(Roles roles)throws Exception{
        HashMap<String, Object>map = new HashMap<String,Object>();
           map.put("FunctionName", roles.getFunctionName());
        map.put("RoleName", roles.getRoleName());
        this.connect.Update("Roles", map,"RoleID="+roles.getRoleID());
       
   }
      public void Updates(HashSet<Roles> roless)throws Exception{
        for(Roles roles:roless)
            this.Update(roles);
       
   }
 public void Delete(Roles roles) throws Exception{
        this.connect.Delete("Roles", "RoleID="+roles.getRoleID());
    }
       public void Deletes(HashSet<Roles> roless) throws Exception {
        for(Roles roles:roless)
            this.Delete(roles);
   }
}